<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>发现-潮聚</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" th:href="@{/css/mui.min.css}" />
		<link rel="stylesheet" th:href="@{/css/common.css}" />
		<link rel="stylesheet" th:href="@{/css/icons-extra.css}" />
		<style>
			.mui-input-row input,
			.mui-input-row textarea {
				margin-bottom: 0;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">发表</h1>
		</header>
		<div class="cj-line-20"></div>
		<div class="mui-content">
			<form>
				<div class="mui-input-row">
					<input name="topic_title" type="email" class="mui-input-clear mui-input" placeholder="标题">
				</div>
				<div class="mui-input-row">
					<textarea id="textarea" rows="5" placeholder="内容" name="topic_content"></textarea>
				</div>
			</form>
			<div class="mui-content-padded">
				<button id='reg' data-loading-text="发表中" id="publish" class="mui-btn mui-btn-block mui-btn-primary cj-btn">发表</button>
			</div>
		</div>
		<div class="cj-line-60"></div>
		<div class="cj-line-20"></div>
		<div th:include="common/footer :: nav"></div>
		<script src="/js/mui.min.js"></script>
		<script src="/js/jquery.min.js"></script>
		<script src="/js/common.js"></script>
		<script>
			$("#publish").click(function() {

				var title = $("input[name='topic_title']").val();
				var content = $("#textarea").val();

				if(title == null || title == "") {
					mui.toast("标题不能为空");
					return;
				}
				if(content == null || content == "") {
					mui.toast("内容不能为空");
					return;
				}

				$.ajax({
					url: "/topic/add",
					data: $("form").serialize(),
					type: 'get',
					dataType: 'json',
					beforeSend: function() {
						mui("#publish").button('loading');
					},
					success: function(response) {
						if(response.code == 200) {
							mui.toast("发表成功");
							location.href = "/topic";
						}
						mui("#publish").button('reset');
					}
				});
			});
		</script>
	</body>

</html>